package GUI;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class Text2 extends JFrame {
    private ArrayList<User> list = new ArrayList<>();
    private LoginPanel loginPanel = new LoginPanel(this);//把ATM机分别传入几个卡片里，就可以调用到ATM机里的属性和方法
    private MenuPanel menuPanel = new MenuPanel(this);
    private CunPanel cunPanel = new CunPanel(this);
    private QuPanel quPanel = new QuPanel(this);
    private ChaPanel chaPanel = new ChaPanel(this);
    private GaiPanel gaiPanel=new GaiPanel(this);
    private ZhuanPanel zhuanPanel=new ZhuanPanel(this);
    private Image bgimg = Utilimg.getImage("/img/background.jpg");
    private Image imageIcon = Utilimg.getImage("/img/icon.png");
    private User loginUser;//作为一个对象属性
    private ArrayList <User> users = new ArrayList();//创建用户集合
    private User userName;//登录成功的用户属性

    public ArrayList<User> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<User> users) {
        this.users = users;
    }

    public User getUserName() {
        return userName;
    }

    public void setUserName(User userName) {
        this.userName = userName;
    }

    public CunPanel getCunPanel() {
        return cunPanel;
    }

    public QuPanel getQuPanel() {
        return quPanel;
    }

    public ChaPanel getChaPanel() {
        return chaPanel;
    }

    public GaiPanel getGaiPanel() {
        return gaiPanel;
    }

    public ZhuanPanel getZhuanPanel() {
        return zhuanPanel;
    }

    private CardLayout cardLayout = new CardLayout();


    public User getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(User loginUser) {
        this.loginUser = loginUser;
    }


    public ArrayList<User> getList() {
        return list;
    }

    public void setList(ArrayList<User> list) {
        this.list = list;
    }

    public Text2() {
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimg, 0, 0, 800, 600, this);
            }
        });
        this.setLayout(cardLayout);
        this.setIconImage(imageIcon);
        this.setTitle("登录");


        this.add("login", loginPanel);
        this.add("menu", menuPanel);
        this.add("cun", cunPanel);
        this.add("qu", quPanel);
        this.add("cha", chaPanel);
        this.add("gai", gaiPanel);
        this.add("zhuan", zhuanPanel);


        this.setSize(800, 600);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    //用户数据初始化
    public void init(){
        users= (ArrayList<User>) FileUtil.readObject("D:/ATM.txt");
    }
    //用户数据保存
    public void preserve(){
        FileUtil.writeObject("D:/ATM.txt",users);
    }
    public void inits() {
        list.add(new User("aaa", "111", 1000));
        list.add(new User("bbb", "222", 500));
        list.add(new User("ccc", "333", 800));
        list.add(new User("ddd", "444", 900));
        list.add(new User("eee", "555", 1200));
    }

    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

    public static void main(String[] args) {
        Text2 text2 = new Text2();
        text2.inits();
    }
}
